package com.yeung.exam;

import java.util.Scanner;

public class 携程_链表排序 {

    public static class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
            next = null;
        }
    }

    /*请完成下面这个函数，实现题目要求的功能
     ******************************开始写代码******************************/
    static ListNode partition(ListNode head, int m) {
        if (head == null || head.next == null) return head;
        ListNode cHead = new ListNode(-1);
        cHead.next = head;
        ListNode low = cHead;
        while (head.next != null) {
            ListNode curNode = head.next;
            if (curNode.val <= m) {
                //先断开
                head.next = curNode.next;
                //再插入进去
                curNode.next = low.next;
                low.next = curNode;
                low.next = head;
            }
            ///移动当前指针
            head = head.next;
        }
        return cHead.next;
    }

    /******************************结束写代码******************************/


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        ListNode head = null;
        ListNode node = null;
        int m = in.nextInt();
        while (in.hasNextInt()) {
            int v = in.nextInt();
            if (head == null) {
                node = new ListNode(v);
                head = node;
            } else {
                node.next = new ListNode(v);
                node = node.next;
            }
        }
        head = partition(head, m);
        if (head != null) {
            System.out.print(head.val);
            head = head.next;
            while (head != null) {
                System.out.print(",");
                System.out.print(head.val);
                head = head.next;
            }
        }
        System.out.println();
    }
}
